package com.bestcem.xm.txtanls.mq;//package com.bestcem.xm.txtanls.mq;
//
//import com.alibaba.fastjson.JSON;
//import com.bestcem.xm.txtanls.grpc.service.param.analysis.LinkageUpdateParam;
//import com.bestcem.xm.txtanls.service.AnalysisProjectService;
//import com.bestcem.xm.txtanls.service.dto.mq.ColumnChanged;
//import com.bestcem.xm.txtanls.service.dto.mq.FreeOrgCreated;
//import com.bestcem.xm.txtanls.service.dto.mq.WorktableChanged;
//import com.bestcem.xm.txtanls.service.util.AnalysisUtil;
//import com.bestcem.xm.txtanls.util.Constants;
//import com.bestcem.xm.util.MsgPackFormatUtil;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.util.Base64;
//
///**
// * @author liheng
// * @version v1.0
// * @date 2021/10/27 11:21
// */
//@Slf4j
//@Component
//public class TxtanlsMqReceiver {
//    private static final Logger EMAIL_LOG = LoggerFactory.getLogger("EmailErrorLog");
//
//    @Resource
//    private AnalysisProjectService analysisProjectService;
//
//    @Resource
//    private AnalysisUtil analysisUtil;
//
//
//    /**
//     * 监听文本分析mq公共消息
//     *
//     * @param dto
//     * @param channel
//     */
//    @RabbitListener(queues = "#{txtanlsQueue.name}", concurrency = "${app.txtanls.rabbitmq.biQueue.concurrency:2}")
//    @RabbitHandler
//    public void handlerAppCommon(Message dto, Channel channel) {
//        try {
//            MsgPackFormatUtil.MqMessage mqMessage = MsgPackFormatUtil.mqDecode(dto.getBody());
//            if (mqMessage == null) {
//                log.error("app消费mq消息解析失败:" + Base64.getEncoder().encodeToString(dto.getBody()));
//                channel.basicNack(dto.getMessageProperties().getDeliveryTag(), false, false);
//                return;
//            }
//            if (log.isInfoEnabled()) {
//                log.info("app消费mq消息收到消息:{}", JSON.toJSONString(mqMessage));
//            }
//
//            if ("bi.worktable_changed".equals(mqMessage.getTopic())) {
//                WorktableChanged worktableChanged = MsgPackFormatUtil.mapToObj(mqMessage.getData(), WorktableChanged.class);
//                analysisProjectService.linkageUpdate(LinkageUpdateParam.getInstance(worktableChanged));
//            }
//            if ("bi.column_changed".equals(mqMessage.getTopic())) {
//                ColumnChanged columnChanged = MsgPackFormatUtil.mapToObj(mqMessage.getData(), ColumnChanged.class);
//                analysisProjectService.linkageUpdate(LinkageUpdateParam.getInstance(columnChanged));
//            }
////            if ("user.free_org_created".equals(mqMessage.getTopic())) {
////                FreeOrgCreated freeOrgCreated = MsgPackFormatUtil.mapToObj(mqMessage.getData(), FreeOrgCreated.class);
////                analysisUtil.initAnalysisProjectForUse(freeOrgCreated.getId());
////            }
//            channel.basicAck(dto.getMessageProperties().getDeliveryTag(), false);
//        } catch (Exception e) {
//            log.error("bi处理倍市得app的mq消息异常:{}" + Base64.getEncoder().encodeToString(dto.getBody()), e);
//            try {
//                channel.basicNack(dto.getMessageProperties().getDeliveryTag(), false, false);
//            } catch (Exception e2) {
//                log.error("处理倍市得app的mq消息, nackmq消息异常", e2);
//            }
//        }
//    }
//
//}
